<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加设备</title>
<%--    <link type="text/css" href="${pageContext.request.contextPath}/static/bootstrap4/css/bootstrap.min.css" rel="stylesheet"/>--%>
<%--    <link type="text/css" href="${pageContext.request.contextPath}/static/css/toastr.min.css" rel="stylesheet"/>--%>
<%--    <link type="text/css" href="${pageContext.request.contextPath}/static/css/adde.css" rel="stylesheet"/>--%>
<%--    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.js"></script>--%>
<%--    <script type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap4/js/bootstrap.min.js"></script>--%>
        <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/toastr.min.js"></script>
         <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/mFrame/newtool.js"></script>
        <style>
            .toast-center-center {
                top: 34%;
                left: 50%;
                margin-top: -30px;
                margin-left: -150px;
            }

        </style>
</head>
<body>
<%
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String tDate = sdf.format(new Date());

%>

<%--格式化日期--%>
<div class="container shadow-sm p-3 mb-5 bg-white rounded">
    <div class="row">
        <div class="col-12">
            <div id="reform" >

                <nav class="navbar  navbar-light rounded " style="background-color: #1e5379; margin-bottom: 30px;">
                    <a class="navbar-brand" href="#" style="color: white;">添加设备</a>
                </nav>
            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-3"></div>
        <div class="col-6">
            <form id="form">
                <div class="form-group row">
                    <label for="eName" class="">设备名称：</label>
                    <div class="col-lg-10">
                        <input type="text" name="eName" class="form-control"id="eName" >
                    </div>
                </div>
                <div class="form-group row">
                    <label for="brand" class="row-lg-2 col-form-label">设备品牌：</label>
                    <div class="col-lg-10">
                        <input type="text" name="brand" class="form-control"  id="brand">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="etype" class="row-lg-2 col-form-label">设备类型：</label>
                    <div class="col-lg-10">
                        <select class="form-control form-control-lg" name="etype" id="etype">
                            <c:forEach var="type" items="${types}">
                                <option value="${type.id}">${type.type}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label for="manufacturer" class="row-lg-2 col-form-label">产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商：</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="manufacturer" id="manufacturer">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="manufacturer" class="row-lg-2 col-form-label">数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="num" id="num">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="deliveryTime" class="row-lg-2 col-form-label">出厂日期：</label>
                    <div class="col-lg-10">
                        <input type="date" class="form-control" name="deliveryTime"  value="<%=tDate%>"  id="deliveryTime"  >
                    </div>
                </div>
                <div class="form-group row">
                    <label for="purchaseTime" class="row-lg-2 col-form-label" >购买时间：</label>
                    <div class="col-lg-10">
                        <input type="date" class="form-control" name="purchaseTime" value="<%=tDate%>" id="purchaseTime">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="purchaseTime" class="row-lg-2 col-form-label" >设备型号：</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="purchaseTime"  id="eModel">
                    </div>
                </div>
                <div class="form-group row">
                    <button  type="button" onclick="sendData()" class="btn btn-success">添加设备</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="button" class="btn btn-primary" id="refreshData">重置</button>
                </div>
            </form>

        </div>
        <div class="col-3"></div>
    </div>
</div>

</body>

<script type="text/javascript">

    var prefixPath="${pageContext.request.contextPath}";
    var notNumber=new RegExp("^(-?[1-9]\\d*\\.?\\d*)|(-?0\\.\\d*[1-9])|(-?[0])|(-?[0]\\.\\d*)$");
    var notNull = new RegExp(".*[^\s]","i");
    $(function () {
        //加载下拉框，不加载会导致失效
        $('.dropdown-toggle').dropdown();
        //请求地址
        customTips();
        //添加数据
        $("#eName").blur(function (){
            var number=$("#eName").val()
            if (!notNull.test(number)){
                StartCheck($(".form-group")[0],"eName","不可为空","sdf",false);
            }else {
                StartCheck($(".form-group")[0],"eName","","sdf",true);
            }

        });

        //刷新界面
        $("#refreshData").click(function (){
            window.parent.frames.detailed("/pj/pageAdd");
        });

        $("#brand").blur(function (){
            var number=$("#brand").val()
             if (!notNull.test(number)){
                 StartCheck($(".form-group")[1],"brand","不可为空","ksdf",false);
             }else {
                 StartCheck($(".form-group")[1],"brand","","ksdf",true);
             }

        });



        $("#manufacturer").blur(function (){
            var number=$("#manufacturer").val()
            if (!notNull.test(number)){
                StartCheck($(".form-group")[3],"manufacturer","不可为空","sfax",false);
            }else {
                StartCheck($(".form-group")[3],"manufacturer","","sfax",true);
            }

        });

        //判断数字类型
        $("#num").blur(function (){
            var number=$("#num").val()
            if (!notNull.test(number)){
                StartCheck($(".form-group")[4],"num","不可为空","jks",false);
            }else if (!notNumber.test(number)){
                StartCheck($(".form-group")[4],"num","输入的不是数值类型","jks",false);
            }else{
                StartCheck($(".form-group")[4],"num","","jks",true);
            }
        });


        //判断型号
        $("#eModel").blur(function (){
            var number=$("#eModel").val()
            if (!notNull.test(number)){
                StartCheck($(".form-group")[7],"eModel","不可为空","emdl",false);
            }else{
                StartCheck($(".form-group")[7],"eModel","","emdl",true);
            }
        });



    });

    function sendData(){
        var url=prefixPath+"/ep/addparam";
        addEquipent(url);

    }




    function  addEquipent(url) {
        var eName=$("#eName").val();
        var brand=$("#brand").val();
        var emodel=$("#eModel").val();
        var mf=$("#manufacturer").val();
        var num=$("#num").val();
        var dtime=$("#deliveryTime").val();
        var goTime=$("#purchaseTime").val();
        var etype=$("#etype").val();
        var newGoTime = (new Date(goTime)).toLocaleDateString().split("/").join('-');
        var newDtime = (new Date(dtime)).toLocaleDateString().split("/").join('-');
        //eName.trim()!=""&&brand.trim()!=""&&emodel.trim()!=""&&
        //mf.trim()!=""&&num.trim()!=""&&dtime.trim()!=""&&goTime.trim()!=""
        if(notNull.test(eName)&&notNull.test(brand)&&notNull.test(emodel)&&notNull.test(mf)&&notNull.test(num)){
            var parmeter={"eid":0,"eName":eName,"etype":{"id":etype,"type":""},"brand":brand,"model":emodel,
                "manufacturer":mf,"num":num,"purchaseTime":newGoTime,"deliveryTime":newDtime};

            $.ajax({
                type: "post",
                dataType:"json",
                contentType:"application/json;charset=utf-8",
                url:url,
                data:JSON.stringify(parmeter),
                success:function (data) {
                    if (data.state){
                        //清空数据
                        toastr.success("新增成功","提示！");
                        setTimeout(function (){
                            window.parent.frames.detailed("/pj/pageAdd");
                        },1500);
                    }else{
                        toastr.error("请检查数据是否有误","提示！");
                    }
                }

            })

        }else{
            toastr.warning("请填写对应的数据","提示！");
        }
    }



    function customTips() {
        toastr.options = {
            closeButton: false, //是否显示关闭按钮
            debug: false, //是否使用debug模式
            positionClass: "toast-center-center",//弹出窗的位置
            showDuration: 300,//显示的动画时间
            hideDuration: 1000,//消失的动画时间
            timeOut: 5000, //展现时间
            extendedTimeOut: 1000,//加长展示时间
            showEasing: "swing",//显示时的动画缓冲方式
            hideEasing: "linear",//消失时的动画缓冲方式
            showMethod: "fadeIn",//显示时的动画方式
            hideMethod: "fadeOut" //消失时的动画方式
        };
    }



</script>


</html>
